const { query } = require('../config/database');
require('dotenv').config();

// 插入基础测试数据
const seedData = async () => {
  try {
    console.log('🌱 开始插入测试数据...');

    // 插入歌手数据
    const artists = [
      ['周杰伦', 'Jay Chou', '中国台湾', '华语流行音乐之王'],
      ['陈奕迅', 'Eason Chan', '中国香港', '香港著名歌手'],
      ['邓丽君', 'Teresa Teng', '中国台湾', '华语歌坛传奇']
    ];

    for (const [name, alias, country, description] of artists) {
      await query(
        'INSERT IGNORE INTO artists (name, alias, country, description) VALUES (?, ?, ?, ?)',
        [name, alias, country, description]
      );
    }
    console.log('✅ 歌手数据插入完成');

    // 插入歌曲数据
    const songs = [
      ['稻香', 1, null, 223, '/assets/default-cover.svg'],
      ['青花瓷', 1, null, 238, '/assets/default-cover.svg'],
      ['孤勇者', 2, null, 256, '/assets/default-cover.svg']
    ];

    for (const [name, artist_id, album_id, duration, cover_url] of songs) {
      await query(
        'INSERT IGNORE INTO songs (name, artist_id, album_id, duration, cover_url) VALUES (?, ?, ?, ?, ?)',
        [name, artist_id, album_id, duration, cover_url]
      );
    }
    console.log('✅ 歌曲数据插入完成');

    console.log('🎉 测试数据插入完成！');

  } catch (error) {
    console.error('❌ 数据插入失败:', error);
  }
};

if (require.main === module) {
  seedData();
}

module.exports = seedData;